package cn.sangedon.review.data.mapper;

import cn.sangedon.review.common.domain.data.TradingDate;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author dongliangqiong
 * @description 针对表【tb_trading_date(交易日历)】的数据库操作Mapper
 * @createDate 2022-08-30 22:23:49
 * @Entity cn.sangedon.review.common.domain.spider.TradingDate
 */
public interface TradingDateMapper extends BaseMapper<TradingDate> {

    @Select("SELECT trading_date FROM tb_trading_date WHERE trading_date <= NOW() ORDER BY trading_date DESC LIMIT #{num}")
    List<String> getLatestTradingDay(@Param("num") Integer num);

    @Select("SELECT trading_date, week_day FROM tb_trading_date WHERE trading_date < #{time} ORDER BY trading_date DESC LIMIT #{num}")
    List<TradingDate> preTradingDay(String time, Integer num);

    @Select("SELECT trading_date, week_day FROM tb_trading_date WHERE trading_date > #{time} ORDER BY trading_date ASC LIMIT #{num}")
    List<TradingDate> postTradingDay(String time, Integer num);

    @Select("SELECT trading_date, week_day FROM tb_trading_date WHERE trading_date >= #{startTime} AND trading_date <= #{endTime} ORDER " +
            "BY trading_date ASC")
    List<TradingDate> betweenTradingDay(String startTime, String endTime);

    @Select("SELECT MIN(trading_date) FROM (SELECT trading_date FROM tb_trading_date WHERE trading_date < #{tradeDate} ORDER BY " +
            "trading_date DESC LIMIT #{ageNum}) t;")
    String getTradeDateAgo(String tradeDate, int ageNum);

    @Select("SELECT COUNT(*) FROM tb_trading_date WHERE trading_date >= #{postTradingDate} AND trading_date <= #{preTradingDate};")
    Integer distance(String preTradingDate, String postTradingDate);
}




